﻿using System;
using System.Collections.Generic;
using System.Security.Permissions;

using Moe.ECamel.Common.Contracts;
using Moe.ECamel.Common.Entities;
using Moe.ECamel.Common.Security;
using Moe.ECamel.Server.BL;

namespace Moe.ECamel.Server.Services
{
	public class PaymentService : ECamelService, IPaymentService
	{
		public PaymentService()
		{
		}

		public PaymentService(ECamelService caller)
			:base(caller)
		{
		}

		[PrincipalPermission(SecurityAction.Demand, Role = Operations.PaymentView)]
		public IList<Payment> GetCustomerPayments(int customerId)
		{
			using (var bl = new PaymentBL(GetReadOnlyDataContext()))
			{
				return bl.GetCustomerPayments(customerId);
			}
		}

		public void AddPayments(IEnumerable<Payment> payments)
		{
			using (var bl = new PaymentBL(GetReadWriteDataContext()))
			{
				bl.AddPayments(payments);
			}

			SubmitChanges();
		}
	}
}
